import { OneModal } from '@/components/one-ui';
import { IOneModalRef } from '@/pages/type';
import React, { Ref, useRef } from 'react';
import { Col, Form, Row, Spin } from 'antd';
import ScrollBarLayout from '@/components/ScrollBarLayout';
import pageStyles from '@/common/pageLayout.less';
import { onCloseModalCommon } from '@/utils';
import '../common/style.less';
import Cls from 'classnames';
import { UploadFormCommon } from '@/components/UploadForm';

interface UpdateNeedMaterialBatchUploadAPI {
  status: Record<string, any>;
  onClose: () => void;
  onSave: (res: Record<string, any>) => void;
}

/**
 * 批量上传论证意见
 * */
export const UpdateNeedMaterialBatchUpload: React.FC<UpdateNeedMaterialBatchUploadAPI> = ({ status, onClose, onSave }) => {
  // 作废表单实例
  const [formRef] = Form.useForm();

  const oneModalRef: Ref<IOneModalRef> = useRef(null); //弹框的ref

  return (
    <>
      <OneModal
        open={true}
        centered={true}
        width={window.screen.width * 0.35}
        ref={oneModalRef}
        title={'批量上传论证意见'}
        onCancel={() => {
          onClose();
        }}
        onOk={() => {
          formRef?.validateFields()?.then((res) => {
            let resObj: Record<string, any> = {};
            if (res?.needProofURL) {
              resObj.needProofURL = res?.needProofURL;
            }
            if (res?.needImportURL) {
              resObj.needImportURL = res?.needImportURL;
            }
            if (res?.needSingleURL) {
              resObj.needSingleURL = res?.needSingleURL;
            }
            onSave(resObj);
            onCloseModalCommon(oneModalRef);
          });
        }}
      >
        <ScrollBarLayout style={{ padding: '0.5rem 0' }}>
          <Spin spinning={false}>
            <div className={Cls(pageStyles['fromView-styles'], 'materialBatchBox')}>
              <Form form={formRef}>
                <Row>
                  <UploadFormCommon
                    form={formRef}
                    label={'需求论证意见'}
                    fileFormName={'needProofURL'}
                    spanCol={24}
                    inRowProportion={24}
                    name={'attachFile'}
                    required={false}
                    accept={'.doc|.docx|.pdf'}
                    url={'/purchaseNeedController/uploadFile'}
                    downloadUrl={'/purchaseNeedController/downloadFile'}
                    fileFormDelName={'delLicenceUrl1'}
                    delFunc={() => {}}
                    uploadSuccessCallback={(url) => {}}
                    maxFile={1}
                    defaultFiles={null}
                    classname="uploadBottomWidth"
                    hintTitle={'如上传多个，只保留第一个！'}
                    fieldBusiPath={'purchase/need'}
                  />
                  <UploadFormCommon
                    form={formRef}
                    label={'进口专业人员论证意见'}
                    fileFormName={'needImportURL'}
                    spanCol={24}
                    inRowProportion={24}
                    name={'attachFile'}
                    required={false}
                    accept={'.doc|.docx|.pdf'}
                    url={'/purchaseNeedController/uploadFile'}
                    downloadUrl={'/purchaseNeedController/downloadFile'}
                    fileFormDelName={'delLicenceUrl2'}
                    delFunc={() => {}}
                    uploadSuccessCallback={(url) => {}}
                    maxFile={1}
                    defaultFiles={null}
                    classname="uploadBottomWidth"
                    hintTitle={'如上传多个，只保留第一个！'}
                    fieldBusiPath={'purchase/need'}
                  />
                  <UploadFormCommon
                    form={formRef}
                    label={'单一来源论证意见'}
                    fileFormName={'needSingleURL'}
                    spanCol={24}
                    inRowProportion={24}
                    name={'attachFile'}
                    required={false}
                    accept={'.doc|.docx|.pdf'}
                    url={'/purchaseNeedController/uploadFile'}
                    downloadUrl={'/purchaseNeedController/downloadFile'}
                    fileFormDelName={'delLicenceUrl3'}
                    delFunc={() => {}}
                    uploadSuccessCallback={(url) => {}}
                    maxFile={1}
                    defaultFiles={null}
                    classname="uploadBottomWidth"
                    hintTitle={'如上传多个，只保留第一个！'}
                    fieldBusiPath={'purchase/need'}
                  />
                </Row>
              </Form>
            </div>
          </Spin>
        </ScrollBarLayout>
      </OneModal>
    </>
  );
};
